
import pygame, random

# 自定义文字管理类
class GameScore(object):

    # 记录分数
    __cls_score = 0

    def __init__(self, font_size):
        self.font = pygame.font.SysFont("SimHei", font_size) # 设置字体和大小
        # render(text(文本内容), antialias(抗锯齿), color(RGB))，返回文字对象
        self.text_obj = self.font.render("分数:0", 1, (255, 255, 255))

    # 设置显示的文字和字体颜色
    def set_text_obj(self):
        
        GameScore.__cls_score += 5 # 加5分
        # 随机颜色值
        r = random.randint(0, 255)
        g = random.randint(0, 255)
        b = random.randint(0, 255)

        # 重新赋值
        self.text_obj = self.font.render("分数:%d" % GameScore.__cls_score, 1, (r, g, b))